<?php
declare (strict_types=1);

namespace app\command;

use app\api\service\WechatService;
use app\api\service\WechatSubscribeService;
use app\model\ActivityStatistics;
use app\model\Money;
use app\model\PayRecord;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;
use think\facade\Queue;

class FixActivityStatisticsTask extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('fix-activity-statistics-task')
            ->addArgument('date_str', Argument::OPTIONAL, '当天时间')
            ->setDescription('修复活动统计数据任务');
    }

    protected function execute(Input $input, Output $output)
    {
        $dateStr = $input->getArgument('date_str');
        if ($dateStr){
            $dateTime = date('Ymd', strtotime($dateStr));
        }else{
            $dateTime = date('Ymd');
        }
        PayRecord::where([
            ['consume_date','=',$dateTime],
            ['activity_id','>',0],
        ])->chunk(1000,function ($items) use($dateTime){
            foreach ($items as $item){
                PayRecord::saveActivityStatistics($item,$dateTime);
            }
        },'id','DESC');
    }
}
